﻿using System;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
using Quartz;

namespace Sayook.Schedule.JobImpl
{
    [DisallowConcurrentExecution]
    [PersistJobDataAfterExecution]
    public class HelloJob : IJob
    {
        private readonly ILogger _logger;
        public HelloJob(ILogger<HelloJob> logger)
        {
            _logger = logger;
        }
        public Task Execute(IJobExecutionContext context)
        {
            var flag = context.JobDetail.JobDataMap.GetInt("flag");
            var jobName = context.MergedJobDataMap["jobName"];

            Console.WriteLine($"{DateTime.Now.ToLongTimeString()}-flag:{flag}-jobName:{jobName}");
            _logger.LogInformation($"{DateTime.Now.ToLongTimeString()}-flag:{flag}-jobName:{jobName}");

            flag++;
            context.JobDetail.JobDataMap.Put("flag", flag);
            Thread.Sleep(2000);

            return Task.CompletedTask;
        }
    }
}